﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;

namespace FYPHP
{
    public partial class AdminForCharges : System.Web.UI.Page
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["fyphp"].ConnectionString);

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                conn.Open();
                SqlCommand cmdSelect = new SqlCommand("SELECT * FROM Charges", conn);
                SqlDataReader dtrSelect = cmdSelect.ExecuteReader();

                dtrSelect.Read();
                txtVirtual.Text = dtrSelect["ch_price"].ToString();
                dtrSelect.Read();
                txtAds.Text = dtrSelect["ch_price"].ToString();

                dtrSelect.Close();
                conn.Close();
            }
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            conn.Open();
            SqlCommand cmdUp = new SqlCommand("UPDATE Charges SET ch_price='"+ txtVirtual.Text +"' WHERE ch_type='Virtual'", conn);
            cmdUp.ExecuteNonQuery();
            cmdUp = new SqlCommand("UPDATE Charges SET ch_price='" + txtAds.Text + "' WHERE ch_type='Ads'", conn);
            cmdUp.ExecuteNonQuery();
            conn.Close();

            MessageBox("Update Successfully!");
        }

        private void MessageBox(string msg)
        {
            Label lbl = new Label();
            lbl.Text = "<script language='javascript'>" + Environment.NewLine + "window.alert('" + msg + "')</script>";
            Page.Controls.Add(lbl);
        }
    }
}